//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;
using ProjectBase.Core;

using $prjsn$.Entity;
using $prjsn$.Common;
using $prjsn$.Common.Data;

namespace $safeprojectname$
{
    public class BusinessObjectTypeFilterValidator : FilterValidatorBase<BusinessObjectType, BusinessObjectTypeFilter, int>
    {
        protected override void Init(RuleCollection<BusinessObjectTypeFilter> rules)
        {
            base.Init(rules);
        }
    }

    public class BusinessObjectTypeValidator : EntityValidatorBase<BusinessObjectType, int, IBusinessObjectTypeDao>
    {
        protected override void Init(RuleCollection<BusinessObjectType> rules)
        {
            // string length

            // unique Name
            rules.For(entity => entity.Name).RequireLengthBetween(1, 50);
            rules.IsUnique(entity => Dao.Find(entity.ID, new BusinessObjectTypeFilter { NameExact = entity.Name }), "Name");

            rules.For(entity => entity.DisplayName).RequireLengthBetween(1, 100);
            rules.IsUnique(entity => Dao.Find(entity.ID, new BusinessObjectTypeFilter { DisplayNameExact = entity.DisplayName }), "DisplayName");

            // TODO
            //rules.Assure(IsBusinessObjectTypeInUse).WhenDeleting();
        }
    }
}